/**
    首先生成两个两个随机数ab,然后看作是a行b列矩阵，即可以生成1-49的数，对于1-40的数，我们可以通过取余的方式获取到均匀的1-10，
 */
class Solution extends SolBase {
    public int rand10() {
        while( true ){
            int num;
            int row = rand7(), col = rand7();
            num = (row-1)*7+col;  // [1..49]
            if( num <= 40 ){
                return num % 10+1;
            }
            // 拒绝41-49
            num -= 40;   // 此时num = [1...9]
            row = num; col = rand7(); 
            num = (row-1)*7+col;  // [1..63]
            if( num <= 60 ){
                return num % 10+1;
            }
            num -= 60;  // [1..3]
            row = num; col = rand7();
            num = (row-1)*7+col;  // [1..21]
            if( num<=20 ){
                return num % 10+1;
            }
        }
    }
}